package com.ch.home.controller.dishController;

import com.ch.home.bean.DishHistory;
import com.ch.home.service.serviceImpl.restDishServiceImpl.DishHistoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * Created by CHEN on 2019/8/28.
 */
@RestController
@RequestMapping("/dish/history")
public class DishHistoryController {


    @Autowired
    DishHistoryServiceImpl dishHistoryService;


    /**
     * 拿到预览信息，目前可以不写
     *
     * @return
     */
    @PostMapping("/getPreview")
    public HashMap getPreview() {
        return null;
    }


    /**
     * @return
     */
    @PostMapping("/getAll")
    public HashMap getAllInfo(@RequestParam(required = false) Integer dishId) {
        HashMap<Object, Object> result;
        result = dishHistoryService.getAll(new DishHistory(null, dishId, null, null, null, null, null));
        return result;
    }

    @PostMapping("/add")
    public HashMap addHistory(@RequestParam(required = false) Integer dishId, @RequestParam(required = false) String historyContent, @RequestParam(required = false) String historyTime, @RequestParam(required = false) Integer order) {

        HashMap<Object, Object> result;
        result = dishHistoryService.add(new DishHistory(null, dishId, historyContent, historyTime, order, null, null));
        return result;
    }


    @PostMapping("/update")
    public HashMap updateHistory(@RequestParam(required = false) Integer historyId,@RequestParam(required = false) Integer dishId, @RequestParam(required = false) String historyContent, @RequestParam(required = false) String historyTime, @RequestParam(required = false) Integer order) {
        HashMap<Object, Object> result;
        result = dishHistoryService.update(new DishHistory(historyId, dishId, historyContent, historyTime, order,null,null));
        return result;
    }


    //comment可以暂时不写


}
